package com.partners.controller.Page;

import com.alibaba.fastjson.JSONObject;
import com.partners.annotation.Auths;
import com.partners.constant.PermissionEnum;
import com.partners.service.UserService;
import com.partners.utils.CodeUtils;
import com.partners.utils.SessionManager;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * @author liangyongle
 * @date 2019-01-21
 */
@Controller
@RequestMapping("configPage")
public class ConfigPageController {

    @Resource
    private UserService userService;


    @Resource
    private SessionManager sessionManager;
    /**
     * 设置
     * */
    @GetMapping("config")
    @Auths
    public ModelAndView taskInfo(HttpSession session, @RequestParam(value="id", required=false) Integer id){
        JSONObject jsonObject = sessionManager.JsonSession(session);
        Integer uid = jsonObject.getInteger("userId");
        //判断是否有权限进入
        Integer code = PermissionEnum.CONFIG_DETAIL.getCode();
        boolean permission = userService.hasPermission(uid, code);
        String viewName = "show/config";
        ModelAndView mav = CodeUtils.checkPermissionView(permission, viewName, code, uid);
        mav.addObject("uid",uid);
        mav.addObject("id",id);
        return mav;
    }

}
